package com.addplus.townmall.server.api.mapper.town;

import com.addplus.townmall.server.api.model.town.AppMainExclusive;
import com.addplus.townmall.server.api.model.town.expand.AppMainExclusiveExpand;
import com.addplus.townmall.server.api.utils.BaseAddMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * App首页会员专享 Mapper 接口
 * </p>
 *
 * @author zhangjiehang
 * @since 2018-11-10
 */
public interface AppMainExclusiveMapper extends BaseAddMapper<AppMainExclusive> {

    @Select("SELECT\n" +
            " a.id,\n" +
            " a.store_id,\n" +
            " s.store_name ,\n" +
            " a.shop_product_id,\n" +
            " a.shop_sku_id,\n" +
            " a.shop_name,\n" +
            " a.shop_tag,\n" +
            " a.shop_seal_img,\n" +
            " a.line_price,\n" +
            " a.sale_price \n" +
            "FROM\n" +
            " app_main_exclusive a\n" +
            " LEFT JOIN store s ON s.id = a.store_id AND s.is_delete = 0\n" +
            " WHERE a.is_deleted = 0\n" +
            " ORDER BY a.sort \n" +
            " limit #{countList}")
    List<AppMainExclusiveExpand> getAppMainExclusiveExpandLimt(@Param("countList") Integer countList);

    @Select("select s.store_name,sku.sku_describe,a.id,a.shop_product_id, a.shop_sku_id, a.shop_name, a.shop_tag, \n" +
            "a.shop_seal_img, a.line_price, a.sale_price ,a.sort\n" +
            "from app_main_exclusive a \n" +
            "LEFT JOIN store s ON s.id = a.store_id AND s.is_delete = 0 \n" +
            "LEFT JOIN shop_specification_sku sku ON a.shop_sku_id = sku.id \n" +
            "where a.is_deleted=0 order by a.gmt_modified desc")
    List<AppMainExclusiveExpand> getAllAppMainExclusive(IPage page);

    @Select("select IFNULL(max(sort)+1,1) as sort from app_main_exclusive where is_deleted=0")
    Integer getMaxSort();

}
